package com.eagle.common.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.eagle.common.entity.enums.PageSize;
import com.eagle.common.entity.po.AdminRoles;
import com.eagle.common.entity.po.query.AdminRolesQuery;
import com.eagle.common.entity.vo.PaginationResult;
import com.eagle.common.entity.vo.SimplePage;
import com.eagle.common.exception.BusinessException;
import com.eagle.common.mapper.AdminRolesMapper;
import com.eagle.common.service.AdminRolesService;



/**
 * 
 * 后台角色表 业务接口实现
 * 
 */
@Service("adminRolesService")
public class AdminRolesServiceImpl implements AdminRolesService {

private static final Logger logger = LoggerFactory.getLogger(AdminRolesServiceImpl.class);	@Resource
	private AdminRolesMapper<AdminRoles,AdminRolesQuery> adminRolesMapper;

	/**
	 * 根据条件查询列表
	 */
	public List<AdminRoles> findListByParam(AdminRolesQuery param) {
		List<AdminRoles> list = this.adminRolesMapper.selectList(param);
		return list;
	}

	/**
	 * 根据条件查询列表
	 */
	public Integer findCountByParam(AdminRolesQuery param) {
		Integer count = this.adminRolesMapper.selectCount(param);
		return count;
	}

	/**
	 * 分页查询方法
	 */
	public PaginationResult<AdminRoles> findListByPage(AdminRolesQuery param) {
		int count = this.adminRolesMapper.selectCount(param);
		int pageSize = param.getPageSize()==null?PageSize.SIZE15.getSize():param.getPageSize();
		int pageNo = 0;
		if (null != param.getPageNo()) {
			pageNo=param.getPageNo();
		}
		SimplePage page = new SimplePage(pageNo, count, pageSize);
		param.setSimplePage(page);
		List<AdminRoles> list = this.adminRolesMapper.selectList(param);
		PaginationResult<AdminRoles> result = new PaginationResult<AdminRoles>(page, list);
		return result;
	}

	/**
	 * 新增
	 */
	public Integer add(AdminRoles bean) throws BusinessException{
		try {
			return this.adminRolesMapper.insert(bean);
		} catch (Exception e) {
			throw new BusinessException("信息已经存在");
		}
	}

	/**
	 * 批量新增
	 */
	public Integer addBatch(List<AdminRoles> listBean){
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.adminRolesMapper.insertBatch(listBean);
	}

	/**
	 * 根据Id修改
	 */
	public Integer updateById(AdminRoles bean,Integer id){
		return this.adminRolesMapper.updateById(bean,id);
	}


	/**
	 * 根据Id删除
	 */
	public Integer deleteById(Integer id){
		return this.adminRolesMapper.deleteById(id);
	}


	/**
	 * 根据Id获取对象
	 */
	public AdminRoles getAdminRolesById(Integer id){
		return this.adminRolesMapper.selectById(id);
	}

}